var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    datalist: [],
    cardnumber: '',
    pageNum: 1,
    flag: true, //触底开关
    noShow: false

  },

  /**
   * 生命周期函数--监听页面加载
   */

  onLoad: function (options) {
    var that = this
    that.setData({
      cardnumber: options.card
    })
    console.log(that.data.cardnumber)
    that.getAxios()
  },
  getAxios() {
    wx.showLoading({
      title: '加载中',
    })
    var that = this
    app.executeRequest(function (header) {
      wx.request({
        url: app.BASE_URL + '/hospitalized/getUserDepositInfo',
        header: header,
        data: {
          cardNum: that.data.cardnumber,
          pageNum: that.data.pageNum
        },
        success: (res) => {
          getApp().hideLoading()
          console.log(res)
          if (!res.data.data) {
            that.setData({
              flag: false,
              noShow: true
            })
          } else {
            that.setData({
              datalist: that.data.datalist.concat(res.data.data),
              noShow: true
            })
          }

        }
      })
    })
  },
  getAxiosed() {
    var that = this
    app.executeRequest(function (header) {
      wx.request({
        url: app.BASE_URL + '/hospitalized/getUserDepositInfo',
        header: header,
        data: {
          cardNum: that.data.cardnumber,
          pageNum: 1
        },
        success: (res) => {
          console.log(res)
          if (!res.data.data) {
            that.setData({
              flag: false,
              noShow: true
            })
          } else {
            that.setData({
              dataList: res.data.data,
              noShow: true
            })
          }

        }
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    var that = this;

    that.getAxiosed();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if (that.data.flag) {
      that.setData({
        pageNum: that.data.pageNum + 1, //每次触发上拉事件，把searchPageNum+1  
      });
      that.getAxios();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})